package com.meowcook.controller;

import com.meowcook.config.AppConfig;
import com.meowcook.common.AppResult;
import com.meowcook.pojo.dto.ReplyDTO;
import com.meowcook.pojo.dto.ReplyListDTO;
import com.meowcook.pojo.vo.ReplyVO;
import com.meowcook.pojo.vo.UserPartIVO;
import com.meowcook.service.IReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 28792
 * Date: 2025-05-18
 * Time: 15:00
 */
@Slf4j
@Api(tags = "回复操作接口")
@RestController
@RequestMapping("/reply")
public class ReplyController {
    @Resource
    private IReplyService replyService;
    @PostMapping("/addReply")
    @ApiOperation("发表回复")
    public AppResult reply(HttpServletRequest request, @Valid @RequestBody ReplyDTO reply) {
        // 获取用户id,并赋值
        UserPartIVO user = (UserPartIVO) request.getSession(false).getAttribute(AppConfig.USER_SESSION_KEY);
        reply.setUserId(user.getId());
        log.info("回复信息：{}", reply);
        // 调用service
        replyService.reply(reply);
        return AppResult.success("回复成功");
    }

    @PostMapping("/getReplyList")
    @ApiOperation("获取回复列表")
    public AppResult<List<ReplyVO>> getReplyList(@Valid @RequestBody ReplyListDTO reply) {
        log.info("查询参数：{}", reply);
        List<ReplyVO> replyList = replyService.selectByCommentId(reply);
        return AppResult.success(replyList);
    }
}
